fix: improved contextual tuples layout for check/batch check#1223
fix: improved contextual tuples layout for check/batch check#1223
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughTwo snippet viewer components in the documentation were updated to reformat generated code examples. The CURL request body output was changed from single-line JSON to multi-line indented format. Additionally, the JS SDK code generation for contextual tuples was modified to use explicit object literal syntax instead of a direct JSON stringification approach. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
Pull request overview
Improves readability of generated documentation snippets by formatting contextual tuples across multiple lines for Check and BatchCheck request examples.
Changes:
- Reformats the Check cURL request JSON payload to multi-line fields (including contextual tuples and context).
- Reformats contextual tuples output for the Check JS SDK snippet.
- Reformats the BatchCheck cURL request JSON payload’s contextual tuples and context sections.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/components/Docs/SnippetViewer/CheckRequestViewer.tsx | Updates Check snippet rendering (cURL + JS SDK) to print contextual tuples in a more readable layout. |
| src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx | Updates BatchCheck cURL snippet rendering to print contextual tuples in a more readable layout. |
Comments suppressed due to low confidence (1)
src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx:416
- The BatchCheck cURL snippet’s
-d '{...payload is not valid JSON as generated: each check object ends with a trailing comma, and thechecksarray / root object are never closed before the snippet moves on to# Response. This makes the copied command unusable; consider building a request-body object and usingJSON.stringify(body, null, 2)to render a correct, pretty-printed payload (like other viewers do).
}${check.context ? `,\n "context": ${JSON.stringify(check.context)}` : ''}
},
`,
)
.join('')}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx (1)
388-418:⚠️ Potential issue | 🔴 CriticalClose the CURL payload and remove the JSON trailing commas.
This template still emits an invalid request body: the
-d '{block never closes before# Response, and the generated JSON keeps trailing commas in bothtuple_keyand thechecksarray items. The batch example will not run as written.💡 Suggested fix
- ${checks - .map( - (check) => ` { + ${checks + .map( + (check, index) => ` { "tuple_key": { "user":"${check.user}", "relation":"${check.relation}", - "object":"${check.object}", - }, + "object":"${check.object}" + }, "correlation_id": "${check.correlation_id}"${ check.contextualTuples ? `, "contextual_tuples": { "tuple_keys": [${check.contextualTuples .map( (tuple) => ` {"user": "${tuple.user}", "relation": "${tuple.relation}", "object": "${tuple.object}"}`, ) .join(',')} ] }` : '' }${check.context ? `,\n "context": ${JSON.stringify(check.context)}` : ''} - }, + }${index < checks.length - 1 ? ',' : ''} `, ) .join('')} + ] +}' # Response:🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx` around lines 388 - 418, The generated curl JSON in BatchCheckRequestViewer.tsx is invalid: fix the template that builds the -d payload (the multi-line template using modelId and checks.map) by removing trailing commas inside each "tuple_key" object and at the end of each check item, ensure the "checks" array items are joined without leaving a trailing comma, properly serialize contextualTuples as a JSON array (no trailing comma) and close the top-level JSON object and the '-d' string (add the closing } and ending quote) so the final payload is valid JSON.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/components/Docs/SnippetViewer/CheckRequestViewer.tsx`:
- Around line 109-115: The snippet in CheckRequestViewer.tsx currently
interpolates tuple.user/relation/object into single-quoted strings (the
contextualTuples rendering), which breaks on quotes/backslashes/newlines and
drops optional fields like condition; change the rendering to serialize each
tuple with JSON.stringify(tuple) (or a safe serializer) when building the
contextualTuples array so all properties (including condition) are preserved and
properly escaped, and keep the same join/indentation logic so the output matches
the SDK request shape.
---
Outside diff comments:
In `@src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx`:
- Around line 388-418: The generated curl JSON in BatchCheckRequestViewer.tsx is
invalid: fix the template that builds the -d payload (the multi-line template
using modelId and checks.map) by removing trailing commas inside each
"tuple_key" object and at the end of each check item, ensure the "checks" array
items are joined without leaving a trailing comma, properly serialize
contextualTuples as a JSON array (no trailing comma) and close the top-level
JSON object and the '-d' string (add the closing } and ending quote) so the
final payload is valid JSON.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7aea2e8f-4af5-4e96-8cf2-04d38f1a6561
📒 Files selected for processing (2)
src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsxsrc/components/Docs/SnippetViewer/CheckRequestViewer.tsx
Description
What problem is being solved?
How is it being solved?
What changes are made to solve it?
In some languages contextual tuples were displayed as a single line, making them hard to read.
Before

** After**

References
Review Checklist
mainSummary by CodeRabbit